package pl.perseus.action;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import lombok.Getter;
import lombok.Setter;

import org.springframework.beans.factory.annotation.Autowired;

import pl.perseus.model.User;
import pl.perseus.service.user.IUserService;

public class GetUsersToDeleteAction extends BaseAction {

	@Autowired
	IUserService userService;
	
	@Getter
	@Setter
	User u;
	
	@Getter
	@Setter
	Map<String, Object> result;
	
	@Override
	public String execute() {
		result = new HashMap<String, Object>();
		List<User> users = userService.getAllExceptCurrent(getCurrentUserLogin());
		List<Map<String, String>> items = new LinkedList<Map<String, String>>();
		for(User u : users){
			Map<String, String> userMap = new HashMap<String, String>();
			userMap.put("id", u.getId().toString());
			userMap.put("name", u.getUsername());
			
			items.add(userMap);
		}
		
		result.put("identifier", "id");
		result.put("items", items);
		
		return SUCCESS;
	}

}
